/*
 * CPoisonWound.java
 *
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 *
 * This file is part of JRogueDPS.
 *
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package dpssystem;

import dpsstats.CDamageStats;
import dpssystem.CAttackChance.HitType;

/**
 *
 * @author Mani
 */
public class CPoisonWound extends CPoison {

    public double m_averageDamage = 231.0; // Wound Poison
    public double m_ppm = 21.43;
    public double m_procChance;
    public double m_vilePoisonBoost;
    public double m_critBoost;

    CPoisonWound(CWeapon p_weapon, CDamageStats p_damageStats, CSim p_sim)
    {
        super("Wound Poison", PoisonType.NONE, p_weapon, p_damageStats, p_sim);
        m_procChance = m_ppm / (60.0 / p_weapon.m_weaponSpeed);
        m_vilePoisonBoost = 1.0 + (Math.min(this.m_sim.m_dpsInterface.m_talents.getVilePoisonsDouble() * 7, 0.2));

        double l_preyOnTheWeak = 1.0 + (this.m_sim.m_dpsInterface.m_talents.getPreyOnTheWeakDouble() * 4.0);
        double l_metaCritBoost = 1.0 + m_sim.m_dpsInterface.m_metaGem.getMetaGemCritBoost();
        double l_murderBoost = 1.0;

        if (m_sim.m_dpsInterface.m_target.isMurderable() && m_sim.m_dpsInterface.m_talents.getMurder() != 0)
        {
            l_murderBoost = 1.0 + 0.02; // 2% boost
        }

        m_critBoost = 1.5 * l_preyOnTheWeak * l_metaCritBoost * l_murderBoost;
    }



    public void procPoison(boolean p_shiv)
    {
        // Wound poison proc is calculated as ppm
        if (p_shiv || this.m_sim.m_rng.nextDouble() < m_procChance)
        {
            // poison procced
            // will it miss/hit or crit
            // Succeeded on proccing a poison, now work out resistances
            HitType l_hitType = this.m_sim.m_attackChance.getSpellHit(
                    this.m_sim.m_baseStats.getSpellHitChance(),
                    this.m_sim.m_baseStats.getSpellCritChance());
            if (l_hitType == HitType.MISS)
            {
                this.m_damageStats.addStats(l_hitType, 0.0);
                return;
            }

            double l_damage;
            // Attack power mod
            l_damage = m_averageDamage + (0.04 * this.m_sim.m_baseStats.getAttackPower());
            l_damage *= m_vilePoisonBoost;

            // No crits for shiv
            if (l_hitType == HitType.CRIT && !p_shiv) {
                l_damage *= m_critBoost;
            }

            // spell resistance reduction;
            l_damage -= (l_damage * 0.06);

            this.m_damageStats.addStats(l_hitType, l_damage);
            this.m_sim.m_target.m_woundPoison.applyWoundPoison();
        }
    }
}
